/**
 * 
 */
package com.xbang.attendance.web.action.system.sign;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.demo2do.lighturl.annotation.Action;
import com.xbang.attendance.entity.Sign.Actioninfo;
import com.xbang.attendance.service.PurchaseOrderService;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Index extends SearchActionSupport {

	private static final long serialVersionUID = 6137752167041062321L;

	private static final Log logger = LogFactory.getLog(Index.class);

	@Autowired
	private PurchaseOrderService purchaseOrderService;

	private List<Actioninfo> actioninfo=new ArrayList<Actioninfo>();
	public List<Map> getMap() {
		return map;
	}

	public void setMap(List<Map> map) {
		this.map = map;
	}

	private List<Map> map = new ArrayList<Map>();


	

	public void setActioninfo(List<Actioninfo> actioninfo) {
		this.actioninfo = actioninfo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	private Integer id;

	@Action("/system/sign/index/${currPageId}")
	public String listByPage() throws Exception {
		
		return list();
	}

	@Action("/system/sign/list")
	public String list() throws Exception {
		Map map1= new HashMap();
		String hqlSentence = "FROM Actioninfo actioninfo WHERE 1 = 1 ";

		if (searchComponent.getOrderParameters().isEmpty()) {
			searchComponent.addSearchElement("orderBy.actioninfo.signinTime", "DESC");
		}

	if (page != null) {
			if (currPageId.intValue() != -1 && currPageId.intValue() > 0) {
				page.setCurrentPage(currPageId);
			}
		}
	
		Result result = purchaseOrderService.searchByPage(hqlSentence, searchComponent, page);
		actioninfo = result.getItems();
		Map map3 = new HashMap();
		String s = null;
		Actioninfo actioninfo1=null;
		Iterator it = actioninfo.iterator();
		for(int i = 0; i<actioninfo.size();i++){
			map3=new HashMap();
			actioninfo1 = new Actioninfo();	
			actioninfo1  =actioninfo.get(i);
			s=actioninfo1.getUserId().toString();
			map3.put("actionType", actioninfo1.getActionType());
			map3.put("actionSubType", actioninfo1.getActionSubType());
			map3.put("signinTime",actioninfo1.getSigninTime());
			map3.put("distance",actioninfo1.getDistance());
			map3.put("deviceType",actioninfo1.getDeviceType());
			map3.put("deviceId",actioninfo1.getDeviceId());
			map3.put("appVersion",actioninfo1.getAppVersion());
			map3.put("gpsTime", actioninfo1.getGpsTime());
			map3.put("lateTime", actioninfo1.getLateTime());
			map3.put("gpsType", actioninfo1.getGpsTime());
			map3.put("locLatitude",actioninfo1.getLocLatitude() );
			map3.put("locLongtitude",actioninfo1.getLocLongtitude());
			map3.put("action_desc",actioninfo1.getAction_desc());
			map3.put("address",String.valueOf(actioninfo1.getAddress()!=null&&!"null".equals(actioninfo1.getAddress())?java.net.URLDecoder.decode(actioninfo1.getAddress(),"utf-8"):""));			
			//java.net.URLEncoder.encode("dsfds");
			map3.put("serverTime",actioninfo1.getServerTime());
			String sql = "select user_name from userinfo where user_id = '"+s+"'";
			List<Map>  s1 = purchaseOrderService.queryForList(sql, map1);
			for(Map map2 : s1){
				String s3 = map2.get("user_name").toString();
				map3.put("userId",s3);
			}
			map.add(map3);
		}
    	page = result.getPage();
		return "index";
	}

	

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub
		
	}

	

}
